Public Class FormDepartments

    Dim myGroup As DataTable
    Private Sub initalizeData()
        Try
            loadData()
        Catch ex As Exception
            Throw ex
        End Try
    End Sub
    Public Sub loadData()
        'Get Data From Database
        Try
            myGroup = Groups.GetDepartment
            dgvDepartment.DataSource = myGroup
        Catch ex As Exception

        End Try
    End Sub

    Public Sub New()

        ' This call is required by the designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.
        Dbinterface.OpenConnection()
        initalizeData()
    End Sub


    
    Private Sub FormDepartments_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        UI.FormatDataGrid(dgvDepartment)
        btnAdd.Enabled = App.IsAuthorized(Permissions.Manage_Department_add)
        btnUpdate.Enabled = App.IsAuthorized(Permissions.Manage_Department_Edit)
        btnDelete.Enabled = App.IsAuthorized(Permissions.Manage_Department_Delete)
    End Sub

    Private Sub btnUpdate_Click(sender As Object, e As EventArgs) Handles btnUpdate.Click
        UpdateDepartment()
    End Sub
    Public Sub UpdateDepartment()


        'pass values from DataGridView to FormDepartmentAED when click Button Update
        Try


            Dim row = Me.dgvDepartment.CurrentRow

            With FormDepartmentAED

                If row.Cells("GROUP_ID").Value Is Nothing Then
                    Exit Sub
                Else
                    .gId = row.Cells("GROUP_ID").Value
                    .txtDepartment.Text = row.Cells("GROUP_NAME").Value

                   
                    .ShowDialog()
                End If

            End With
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub

    Private Sub btnAdd_Click(sender As Object, e As EventArgs) Handles btnAdd.Click
        'Get last DataGridView Rows when click button add
        Dim i = dgvDepartment.Rows.Count.ToString
        i = i - 1
        dgvDepartment.CurrentCell = dgvDepartment.Rows(i).Cells(1)
        Dim frm As New FormDepartmentAED
        frm.ShowDialog()
    End Sub
 
    Private Sub btnDelete_Click(sender As Object, e As EventArgs) Handles btnDelete.Click

    End Sub
End Class